package org.ant.gui.panes;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import org.ant.ctrl.CodesManager;
import org.ant.gui.panes.ACtextpanel.ACTextPanel;
import org.ant.gui.panes.ACtextpanel.CodeEditPane;

public class InputTabbedPane extends JTabbedPane implements ActionListener {

	public InputTabbedPane() {
		super();
		init();
		loadComponents();
	}

	protected void init() {
		addChangeListener(CodesManager.getInstane());
	}

	protected void loadComponents() {
	}

	public CodeEditPane getCurrentPane() {
		return (CodeEditPane) this.getSelectedComponent();
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() instanceof CodesManager) {
			if (!e.getActionCommand().equals(CodesManager.INF_CHANGETAB)) {
				CodesManager codesManager = CodesManager.getInstane();
				if (codesManager.getCodesSize() > getComponentCount()) {
					for (int i = getComponentCount(); i < codesManager
							.getCodesSize(); i++) {
						CodeEditPane pane = new ACTextPanel();
						if (codesManager.getCode(i).getPath() != null) {
							pane.load(codesManager.getCode(i).getPath());
						}
						add(new File(pane.getName()).getName(), (JPanel) pane);
						setSelectedIndex(codesManager.getCurrent());
					}
				}
			}
		}
	}
}
